

clRF1101::clRF1101(clSPI *lpSPI, PortStruct Port, ePins lCSPin): clSPIDeviceWReg(lpSPI, Port, lCSPin){
//	SPISettings.CSPin			= lCSPin;
//	SPISettings.BurstSignal		= false;
//	SPISettings.WaitMISOSignal	= true;
	SPISettings.SPIProgSignalSettings.CSDuration	= 0;
	
	uint8_t lCommand[2];
	lCommand[0]	= 0x0002; lCommand[1]	= 0x06;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x0003; lCommand[1]	= 0x47;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x0008; lCommand[1]	= 0x05;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x000A; lCommand[1]	= 0x02;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x000B; lCommand[1]	= 0x06;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x000D; lCommand[1]	= 0x10;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x000E; lCommand[1]	= 0xB1;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x000F; lCommand[1]	= 0x3B;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x0010; lCommand[1]	= 0xF6;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x0011; lCommand[1]	= 0x83;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x0012; lCommand[1]	= 0x13;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x0015; lCommand[1]	= 0x15;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x0018; lCommand[1]	= 0x18;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x0019; lCommand[1]	= 0x16;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x0020; lCommand[1]	= 0xFB;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x0023; lCommand[1]	= 0xE9;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x0024; lCommand[1]	= 0x2A;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x0025; lCommand[1]	= 0x00;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x0026; lCommand[1]	= 0x1F;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x002C; lCommand[1]	= 0x81;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x002D; lCommand[1]	= 0x35;
	lpSPI->SendData(this, lCommand, 2);
	lCommand[0]	= 0x002E; lCommand[1]	= 0x09;
	lpSPI->SendData(this, lCommand, 2);
	
	
	
}

unsigned char clRF1101::GetRXBufferSize(void){
	unsigned char SendData[2]	= {CCxxx0_RXBYTES, 0};
	pSPI->SendData(this, SendData, 2);
	return SendData[1] & BYTES_IN_RXTXFIFO;
}

unsigned char clRF1101::GetStatus(void){
	unsigned char Data	= 0x3D;
	this->pSPI->SendData(this, &Data, 1);
	return Data;
}

bool clRF1101::ReadBufSingle(unsigned char *Byte){
	if (!GetRXBufferSize()){
		return false;
	}
	
	unsigned char SendData[2]	= {CCxxx0_RXBUF, 0};
	pSPI->SendData(this, SendData, 2);
	
	*Byte	= SendData[1];
	return true;
}

unsigned char clRF1101::GetTXBufferSize(void){
	unsigned char SendData[2]	= {CCxxx0_TXBYTES, 0};
	pSPI->SendData(this, SendData, 2);
	return SendData[1] & BYTES_IN_RXTXFIFO;
}

void clRF1101::WriteBufSingle(unsigned char *Byte){
	unsigned char SendData[2]	= {CCxxx0_TXBUF, *Byte};
	pSPI->SendData(this, SendData, 2);
}

void clRF1101::RFInit(){
	unsigned char Data[2];
	
	Data[0]	= 0x0002;
	Data[1]	= 0x06;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0003;
	Data[1]	= 0x47;
	pSPI->SendData(this, Data, 2);

	Data[0]	= 0x0004;
	Data[1]	= 0xD3;
	pSPI->SendData(this, Data, 2);

	Data[0]	= 0x0005;
	Data[1]	= 0x91;
	pSPI->SendData(this, Data, 2);

	Data[0]	= 0x0006;
	Data[1]	= 0xFF;
	pSPI->SendData(this, Data, 2);

	Data[0]	= 0x0007;
	Data[1]	= 0x07;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0008;
	Data[1]	= 0x05;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x000A;
	Data[1]	= 0x4F;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x000B;
	Data[1]	= 0x06;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x000D;
	Data[1]	= 0x10;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x000E;
	Data[1]	= 0xB1;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x000F;
	Data[1]	= 0x3B;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0010;
	Data[1]	= 0xF6;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0011;
	Data[1]	= 0x83;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0012;
	Data[1]	= 0x17;//0x13;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0013;
	Data[1]	= 0x22;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0014;
	Data[1]	= 0xF8;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0015;
	Data[1]	= 0x15;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0016;
	Data[1]	= 0x07;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0017;
	Data[1]	= 0x30;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0018;
	Data[1]	= 0x18;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0019;
	Data[1]	= 0x16;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0020;
	Data[1]	= 0xFB;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0023;
	Data[1]	= 0xE9;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0024;
	Data[1]	= 0x2A;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0025;
	Data[1]	= 0x00;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0026;
	Data[1]	= 0x1F;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x002C;
	Data[1]	= 0x81;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x002D;
	Data[1]	= 0x35;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x002E;
	Data[1]	= 0x09;
	pSPI->SendData(this, Data, 2);
	
	Data[0]	= 0x0040;
	Data[1]	= 0x60;
	pSPI->SendData(this, Data, 2);
	
	
}